<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionView::Helpers::UrlHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionView::Helpers::UrlHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/actionpack/lib/action_view/helpers/url_helper_rb.html">
                vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Provides a set of methods for making links and getting URLs that depend on
the routing subsystem (see <a
href="../../ActionController/Routing.html">ActionController::Routing</a>).
This allows you to use the same format for links in views and controllers.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000914">button_to</a>&nbsp;&nbsp;
      <a href="#M000919">current_page?</a>&nbsp;&nbsp;
      <a href="#M000913">link_to</a>&nbsp;&nbsp;
      <a href="#M000917">link_to_if</a>&nbsp;&nbsp;
      <a href="#M000916">link_to_unless</a>&nbsp;&nbsp;
      <a href="#M000915">link_to_unless_current</a>&nbsp;&nbsp;
      <a href="#M000918">mail_to</a>&nbsp;&nbsp;
      <a href="#M000912">url_for</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="JavaScriptHelper.html">JavaScriptHelper</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000914" class="method-detail">
        <a name="M000914"></a>

        <div class="method-heading">
          <a href="#M000914" class="method-signature">
          <span class="method-name">button_to</span><span class="method-args">(name, options = {}, html_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Generates a form containing a single button that submits to the URL created
by the set of <tt>options</tt>. This is the safest method to ensure links
that cause changes to your data are not triggered by search bots or
accelerators. If the HTML button does not work with your layout, you can
also consider using the <a href="UrlHelper.html#M000913">link_to</a> method
with the <tt>:method</tt> modifier as described in the <a
href="UrlHelper.html#M000913">link_to</a> documentation.
</p>
<p>
The generated FORM element has a class name of <tt>button-to</tt> to allow
styling of the form itself and its children. You can control the form
submission and input element behavior using <tt>html_options</tt>. This
method accepts the <tt>:method</tt> and <tt>:confirm</tt> modifiers
described in the <a href="UrlHelper.html#M000913">link_to</a>
documentation. If no <tt>:method</tt> modifier is given, it will default to
performing a POST operation. You can also disable the button by passing
<tt>:disabled =&gt; true</tt> in <tt>html_options</tt>. If you are using
RESTful routes, you can pass the <tt>:method</tt> to change the HTTP verb
used to submit the form.
</p>
<h4>Options</h4>
<p>
The <tt>options</tt> hash accepts the same options at <a
href="UrlHelper.html#M000912">url_for</a>.
</p>
<p>
There are a few special <tt>html_options</tt>:
</p>
<ul>
<li><tt>:method</tt> &#8212; specifies the anchor name to be appended to the
path.

</li>
<li><tt>:disabled</tt> &#8212; specifies the anchor name to be appended to the
path.

</li>
<li><tt>:confirm</tt> &#8212; This will add a JavaScript confirm prompt with
the question specified. If the user accepts, the link is processed
normally, otherwise no action is taken.

</li>
</ul>
<h4>Examples</h4>
<pre>
  &lt;%= button_to &quot;New&quot;, :action =&gt; &quot;new&quot; %&gt;
  # =&gt; &quot;&lt;form method=&quot;post&quot; action=&quot;/controller/new&quot; class=&quot;button-to&quot;&gt;
  #      &lt;div&gt;&lt;input value=&quot;New&quot; type=&quot;submit&quot; /&gt;&lt;/div&gt;
  #    &lt;/form&gt;&quot;

  button_to &quot;Delete Image&quot;, { :action =&gt; &quot;delete&quot;, :id =&gt; @image.id },
            :confirm =&gt; &quot;Are you sure?&quot;, :method =&gt; :delete
  # =&gt; &quot;&lt;form method=&quot;post&quot; action=&quot;/images/delete/1&quot; class=&quot;button-to&quot;&gt;
  #      &lt;div&gt;
  #        &lt;input type=&quot;hidden&quot; name=&quot;_method&quot; value=&quot;delete&quot; /&gt;
  #        &lt;input onclick=&quot;return confirm('Are you sure?');&quot;
  #              value=&quot;Delete&quot; type=&quot;submit&quot; /&gt;
  #      &lt;/div&gt;
  #    &lt;/form&gt;&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000914-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000914-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 202</span>
202:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">button_to</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
203:         <span class="ruby-identifier">html_options</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">stringify_keys</span>
204:         <span class="ruby-identifier">convert_boolean_attributes!</span>(<span class="ruby-identifier">html_options</span>, <span class="ruby-node">%w( disabled )</span>)
205: 
206:         <span class="ruby-identifier">method_tag</span> = <span class="ruby-value str">''</span>
207:         <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">method</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'method'</span>)) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-node">%w{put delete}</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_s</span>)
208:           <span class="ruby-identifier">method_tag</span> = <span class="ruby-identifier">tag</span>(<span class="ruby-value str">'input'</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'hidden'</span>, <span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'_method'</span>, <span class="ruby-identifier">:value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_s</span>)
209:         <span class="ruby-keyword kw">end</span>
210: 
211:         <span class="ruby-identifier">form_method</span> = <span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'get'</span> <span class="ruby-operator">?</span> <span class="ruby-value str">'get'</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'post'</span>
212:         
213:         <span class="ruby-identifier">request_token_tag</span> = <span class="ruby-value str">''</span>
214:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">form_method</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'post'</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">protect_against_forgery?</span>
215:           <span class="ruby-identifier">request_token_tag</span> = <span class="ruby-identifier">tag</span>(<span class="ruby-identifier">:input</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;hidden&quot;</span>, <span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">request_forgery_protection_token</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">:value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">form_authenticity_token</span>)
216:         <span class="ruby-keyword kw">end</span>
217:         
218:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">confirm</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;confirm&quot;</span>)
219:           <span class="ruby-identifier">html_options</span>[<span class="ruby-value str">&quot;onclick&quot;</span>] = <span class="ruby-node">&quot;return #{confirm_javascript_function(confirm)};&quot;</span>
220:         <span class="ruby-keyword kw">end</span>
221: 
222:         <span class="ruby-identifier">url</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">options</span>)
223:         <span class="ruby-identifier">name</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">url</span>
224: 
225:         <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-value str">&quot;type&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;submit&quot;</span>, <span class="ruby-value str">&quot;value&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">name</span>)
226: 
227:         <span class="ruby-node">&quot;&lt;form method=\&quot;#{form_method}\&quot; action=\&quot;#{escape_once url}\&quot; class=\&quot;button-to\&quot;&gt;&lt;div&gt;&quot;</span> <span class="ruby-operator">+</span>
228:           <span class="ruby-identifier">method_tag</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tag</span>(<span class="ruby-value str">&quot;input&quot;</span>, <span class="ruby-identifier">html_options</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">request_token_tag</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;&lt;/div&gt;&lt;/form&gt;&quot;</span>
229:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000919" class="method-detail">
        <a name="M000919"></a>

        <div class="method-heading">
          <a href="#M000919" class="method-signature">
          <span class="method-name">current_page?</span><span class="method-args">(options)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if the current request URI was generated by the given
<tt>options</tt>.
</p>
<h4>Examples</h4>
<p>
Let&#8216;s say we&#8216;re in the <tt>/shop/checkout</tt> action.
</p>
<pre>
  current_page?(:action =&gt; 'process')
  # =&gt; false

  current_page?(:controller =&gt; 'shop', :action =&gt; 'checkout')
  # =&gt; true

  current_page?(:action =&gt; 'checkout')
  # =&gt; true

  current_page?(:controller =&gt; 'library', :action =&gt; 'checkout')
  # =&gt; false
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000919-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000919-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 435</span>
435:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_page?</span>(<span class="ruby-identifier">options</span>)
436:         <span class="ruby-identifier">url_string</span> = <span class="ruby-constant">CGI</span>.<span class="ruby-identifier">escapeHTML</span>(<span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">options</span>))
437:         <span class="ruby-identifier">request</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">request</span>
438:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url_string</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\w+:\/\//</span>
439:           <span class="ruby-identifier">url_string</span> <span class="ruby-operator">==</span> <span class="ruby-node">&quot;#{request.protocol}#{request.host_with_port}#{request.request_uri}&quot;</span>
440:         <span class="ruby-keyword kw">else</span>
441:           <span class="ruby-identifier">url_string</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">request_uri</span>
442:         <span class="ruby-keyword kw">end</span>
443:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000913" class="method-detail">
        <a name="M000913"></a>

        <div class="method-heading">
          <a href="#M000913" class="method-signature">
          <span class="method-name">link_to</span><span class="method-args">(name, options = {}, html_options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a link tag of the given <tt>name</tt> using a URL created by the
set of <tt>options</tt>. See the valid options in the documentation for <a
href="UrlHelper.html#M000912">url_for</a>. It&#8216;s also possible to pass
a string instead of an options hash to get a link tag that uses the value
of the string as the href for the link, or use +:back+ to link to the
referrer - a JavaScript back link will be used in place of a referrer if
none exists. If nil is passed as a name, the link itself will become the
name.
</p>
<h4>Options</h4>
<ul>
<li><tt>:confirm =&gt; &#8216;question?&#8216;</tt> &#8212; This will add a
JavaScript confirm prompt with the question specified. If the user accepts,
the link is processed normally, otherwise no action is taken.

</li>
<li><tt>:popup =&gt; true || array of window options</tt> &#8212; This will
force the link to open in a popup window. By passing true, a default
browser window will be opened with the URL. You can also specify an array
of options that are passed-thru to JavaScripts window.open method.

</li>
<li><tt>:method =&gt; symbol of HTTP verb</tt> &#8212; This modifier will
dynamically create an HTML form and immediately submit the form for
processing using the HTTP verb specified. Useful for having links perform a
POST operation in dangerous actions like deleting a record (which search
bots can follow while spidering your site). Supported verbs are :post,
:delete and :put. Note that if the user has JavaScript disabled, the
request will fall back to using GET. If you are relying on the POST
behavior, you should check for it in your controller&#8216;s action by
using the request object&#8216;s methods for post?, delete? or put?.

</li>
<li>The <tt>html_options</tt> will accept a hash of html attributes for the
link tag.

</li>
</ul>
<p>
Note that if the user has JavaScript disabled, the request will fall back
to using GET. If :href=&gt;&#8217;#&#8217; is used and the user has
JavaScript disabled clicking the link will have no effect. If you are
relying on the POST behavior, your should check for it in your
controller&#8216;s action by using the request object&#8216;s methods for
post?, delete? or put?.
</p>
<p>
You can mix and match the <tt>html_options</tt> with the exception of
:popup and :method which will raise an ActionView::ActionViewError
exception.
</p>
<h4>Examples</h4>
<pre>
  link_to &quot;Visit Other Site&quot;, &quot;http://www.rubyonrails.org/&quot;, :confirm =&gt; &quot;Are you sure?&quot;
  # =&gt; &lt;a href=&quot;http://www.rubyonrails.org/&quot; onclick=&quot;return confirm('Are you sure?');&quot;&gt;Visit Other Site&lt;/a&gt;

  link_to &quot;Help&quot;, { :action =&gt; &quot;help&quot; }, :popup =&gt; true
  # =&gt; &lt;a href=&quot;/testing/help/&quot; onclick=&quot;window.open(this.href);return false;&quot;&gt;Help&lt;/a&gt;

  link_to &quot;View Image&quot;, { :action =&gt; &quot;view&quot; }, :popup =&gt; ['new_window_name', 'height=300,width=600']
  # =&gt; &lt;a href=&quot;/testing/view/&quot; onclick=&quot;window.open(this.href,'new_window_name','height=300,width=600');return false;&quot;&gt;View Image&lt;/a&gt;

  link_to &quot;Delete Image&quot;, { :action =&gt; &quot;delete&quot;, :id =&gt; @image.id }, :confirm =&gt; &quot;Are you sure?&quot;, :method =&gt; :delete
  # =&gt; &lt;a href=&quot;/testing/delete/9/&quot; onclick=&quot;if (confirm('Are you sure?')) { var f = document.createElement('form');
       f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
       var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
       m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;&quot;&gt;Delete Image&lt;/a&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000913-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000913-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 137</span>
137:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = <span class="ruby-keyword kw">nil</span>)
138:         <span class="ruby-identifier">url</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">options</span>
139:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
140:             <span class="ruby-identifier">options</span>
141:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:back</span>
142:             <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">env</span>[<span class="ruby-value str">&quot;HTTP_REFERER&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'javascript:history.back()'</span>
143:           <span class="ruby-keyword kw">else</span>
144:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">options</span>)
145:           <span class="ruby-keyword kw">end</span>
146: 
147:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">html_options</span>
148:           <span class="ruby-identifier">html_options</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">stringify_keys</span>
149:           <span class="ruby-identifier">href</span> = <span class="ruby-identifier">html_options</span>[<span class="ruby-value str">'href'</span>]
150:           <span class="ruby-identifier">convert_options_to_javascript!</span>(<span class="ruby-identifier">html_options</span>, <span class="ruby-identifier">url</span>)
151:           <span class="ruby-identifier">tag_options</span> = <span class="ruby-identifier">tag_options</span>(<span class="ruby-identifier">html_options</span>)
152:         <span class="ruby-keyword kw">else</span>
153:           <span class="ruby-identifier">tag_options</span> = <span class="ruby-keyword kw">nil</span>
154:         <span class="ruby-keyword kw">end</span>
155:         
156:         <span class="ruby-identifier">href_attr</span> = <span class="ruby-node">&quot;href=\&quot;#{url}\&quot;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">href</span>
157:         <span class="ruby-node">&quot;&lt;a #{href_attr}#{tag_options}&gt;#{name || url}&lt;/a&gt;&quot;</span>
158:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000917" class="method-detail">
        <a name="M000917"></a>

        <div class="method-heading">
          <a href="#M000917" class="method-signature">
          <span class="method-name">link_to_if</span><span class="method-args">(condition, name, options = {}, html_options = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a link tag of the given <tt>name</tt> using a URL created by the
set of <tt>options</tt> if <tt>condition</tt> is true, in which case only
the name is returned. To specialize the default behavior, you can pass a
block that accepts the name or the full argument list for <a
href="UrlHelper.html#M000916">link_to_unless</a> (see the examples in <a
href="UrlHelper.html#M000916">link_to_unless</a>).
</p>
<h4>Examples</h4>
<pre>
  &lt;%= link_to_if(@current_user.nil?, &quot;Login&quot;, { :controller =&gt; &quot;sessions&quot;, :action =&gt; &quot;new&quot; }) %&gt;
  # If the user isn't logged in...
  # =&gt; &lt;a href=&quot;/sessions/new/&quot;&gt;Login&lt;/a&gt;

  &lt;%=
     link_to_if(@current_user.nil?, &quot;Login&quot;, { :controller =&gt; &quot;sessions&quot;, :action =&gt; &quot;new&quot; }) do
       link_to(@current_user.login, { :controller =&gt; &quot;accounts&quot;, :action =&gt; &quot;show&quot;, :id =&gt; @current_user })
     end
  %&gt;
  # If the user isn't logged in...
  # =&gt; &lt;a href=&quot;/sessions/new/&quot;&gt;Login&lt;/a&gt;
  # If they are logged in...
  # =&gt; &lt;a href=&quot;/accounts/show/3&quot;&gt;my_username&lt;/a&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000917-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000917-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 326</span>
326:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_if</span>(<span class="ruby-identifier">condition</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
327:         <span class="ruby-identifier">link_to_unless</span> <span class="ruby-operator">!</span><span class="ruby-identifier">condition</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
328:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000916" class="method-detail">
        <a name="M000916"></a>

        <div class="method-heading">
          <a href="#M000916" class="method-signature">
          <span class="method-name">link_to_unless</span><span class="method-args">(condition, name, options = {}, html_options = {}) {|name| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a link tag of the given <tt>name</tt> using a URL created by the
set of <tt>options</tt> unless <tt>condition</tt> is true, in which case
only the name is returned. To specialize the default behavior (i.e., show a
login link rather than just the plaintext link text), you can pass a block
that accepts the name or the full argument list for <a
href="UrlHelper.html#M000916">link_to_unless</a>.
</p>
<h4>Examples</h4>
<pre>
  &lt;%= link_to_unless(@current_user.nil?, &quot;Reply&quot;, { :action =&gt; &quot;reply&quot; }) %&gt;
  # If the user is logged in...
  # =&gt; &lt;a href=&quot;/controller/reply/&quot;&gt;Reply&lt;/a&gt;

  &lt;%=
     link_to_unless(@current_user.nil?, &quot;Reply&quot;, { :action =&gt; &quot;reply&quot; }) do |name|
       link_to(name, { :controller =&gt; &quot;accounts&quot;, :action =&gt; &quot;signup&quot; })
     end
  %&gt;
  # If the user is logged in...
  # =&gt; &lt;a href=&quot;/controller/reply/&quot;&gt;Reply&lt;/a&gt;
  # If not...
  # =&gt; &lt;a href=&quot;/accounts/signup&quot;&gt;Reply&lt;/a&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000916-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000916-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 294</span>
294:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_unless</span>(<span class="ruby-identifier">condition</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
295:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">condition</span>
296:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
297:             <span class="ruby-identifier">block</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>)
298:           <span class="ruby-keyword kw">else</span>
299:             <span class="ruby-identifier">name</span>
300:           <span class="ruby-keyword kw">end</span>
301:         <span class="ruby-keyword kw">else</span>
302:           <span class="ruby-identifier">link_to</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>)
303:         <span class="ruby-keyword kw">end</span>
304:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000915" class="method-detail">
        <a name="M000915"></a>

        <div class="method-heading">
          <a href="#M000915" class="method-signature">
          <span class="method-name">link_to_unless_current</span><span class="method-args">(name, options = {}, html_options = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a link tag of the given <tt>name</tt> using a URL created by the
set of <tt>options</tt> unless the current request URI is the same as the
links, in which case only the name is returned (or the given block is
yielded, if one exists). You can give <a
href="UrlHelper.html#M000915">link_to_unless_current</a> a block which will
specialize the default behavior (e.g., show a &quot;Start Here&quot; link
rather than the link&#8216;s text).
</p>
<h4>Examples</h4>
<p>
Let&#8216;s say you have a navigation menu&#8230;
</p>
<pre>
  &lt;ul id=&quot;navbar&quot;&gt;
    &lt;li&gt;&lt;%= link_to_unless_current(&quot;Home&quot;, { :action =&gt; &quot;index&quot; }) %&gt;&lt;/li&gt;
    &lt;li&gt;&lt;%= link_to_unless_current(&quot;About Us&quot;, { :action =&gt; &quot;about&quot; }) %&gt;&lt;/li&gt;
  &lt;/ul&gt;
</pre>
<p>
If in the &quot;about&quot; action, it will render&#8230;
</p>
<pre>
  &lt;ul id=&quot;navbar&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;/controller/index&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;About Us&lt;/li&gt;
  &lt;/ul&gt;
</pre>
<p>
&#8230;but if in the &quot;home&quot; action, it will render:
</p>
<pre>
  &lt;ul id=&quot;navbar&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;/controller/index&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;/controller/about&quot;&gt;About Us&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
</pre>
<p>
The implicit block given to <a
href="UrlHelper.html#M000915">link_to_unless_current</a> is evaluated if
the current action is the action given. So, if we had a comments page and
wanted to render a &quot;Go Back&quot; link instead of a link to the
comments page, we could do something like this&#8230;
</p>
<pre>
   &lt;%=
       link_to_unless_current(&quot;Comment&quot;, { :controller =&gt; 'comments', :action =&gt; 'new}) do
          link_to(&quot;Go back&quot;, { :controller =&gt; 'posts', :action =&gt; 'index' })
       end
    %&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000915-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000915-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 270</span>
270:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_unless_current</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
271:         <span class="ruby-identifier">link_to_unless</span> <span class="ruby-identifier">current_page?</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
272:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000918" class="method-detail">
        <a name="M000918"></a>

        <div class="method-heading">
          <a href="#M000918" class="method-signature">
          <span class="method-name">mail_to</span><span class="method-args">(email_address, name = nil, html_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a mailto link tag to the specified <tt>email_address</tt>, which is
also used as the name of the link unless <tt>name</tt> is specified.
Additional HTML attributes for the link can be passed in
<tt>html_options</tt>.
</p>
<p>
<a href="UrlHelper.html#M000918">mail_to</a> has several methods for
hindering email harvesters and customizing the email itself by passing
special keys to <tt>html_options</tt>.
</p>
<h4>Options</h4>
<ul>
<li><tt>:encode</tt> - This key will accept the strings &quot;javascript&quot;
or &quot;hex&quot;. Passing &quot;javascript&quot; will dynamically create
and encode the mailto: link then eval it into the DOM of the page. This
method will not show the link on the page if the user has JavaScript
disabled. Passing &quot;hex&quot; will hex encode the
<tt>email_address</tt> before outputting the mailto: link.

</li>
<li><tt>:replace_at</tt> - When the link <tt>name</tt> isn&#8216;t provided,
the <tt>email_address</tt> is used for the link label. You can use this
option to obfuscate the <tt>email_address</tt> by substituting the @ sign
with the string given as the value.

</li>
<li><tt>:replace_dot</tt> - When the link <tt>name</tt> isn&#8216;t provided,
the <tt>email_address</tt> is used for the link label. You can use this
option to obfuscate the <tt>email_address</tt> by substituting the . in the
email with the string given as the value.

</li>
<li><tt>:subject</tt> - Preset the subject line of the email.

</li>
<li><tt>:body</tt> - Preset the body of the email.

</li>
<li><tt>:cc</tt> - Carbon Copy addition recipients on the email.

</li>
<li><tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.

</li>
</ul>
<h4>Examples</h4>
<pre>
  mail_to &quot;me@domain.com&quot;
  # =&gt; &lt;a href=&quot;mailto:me@domain.com&quot;&gt;me@domain.com&lt;/a&gt;

  mail_to &quot;me@domain.com&quot;, &quot;My email&quot;, :encode =&gt; &quot;javascript&quot;
  # =&gt; &lt;script type=&quot;text/javascript&quot;&gt;eval(unescape('%64%6f%63...%6d%65%6e'))&lt;/script&gt;

  mail_to &quot;me@domain.com&quot;, &quot;My email&quot;, :encode =&gt; &quot;hex&quot;
  # =&gt; &lt;a href=&quot;mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d&quot;&gt;My email&lt;/a&gt;

  mail_to &quot;me@domain.com&quot;, nil, :replace_at =&gt; &quot;_at_&quot;, :replace_dot =&gt; &quot;_dot_&quot;, :class =&gt; &quot;email&quot;
  # =&gt; &lt;a href=&quot;mailto:me@domain.com&quot; class=&quot;email&quot;&gt;me_at_domain_dot_com&lt;/a&gt;

  mail_to &quot;me@domain.com&quot;, &quot;My email&quot;, :cc =&gt; &quot;ccaddress@domain.com&quot;,
           :subject =&gt; &quot;This is an example email&quot;
  # =&gt; &lt;a href=&quot;mailto:me@domain.com?cc=ccaddress@domain.com&amp;subject=This%20is%20an%20example%20email&quot;&gt;My email&lt;/a&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000918-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000918-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 372</span>
372:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mail_to</span>(<span class="ruby-identifier">email_address</span>, <span class="ruby-identifier">name</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">html_options</span> = {})
373:         <span class="ruby-identifier">html_options</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">stringify_keys</span>
374:         <span class="ruby-identifier">encode</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;encode&quot;</span>).<span class="ruby-identifier">to_s</span>
375:         <span class="ruby-identifier">cc</span>, <span class="ruby-identifier">bcc</span>, <span class="ruby-identifier">subject</span>, <span class="ruby-identifier">body</span> = <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;cc&quot;</span>), <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;bcc&quot;</span>), <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;subject&quot;</span>), <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;body&quot;</span>)
376: 
377:         <span class="ruby-identifier">string</span> = <span class="ruby-value str">''</span>
378:         <span class="ruby-identifier">extras</span> = <span class="ruby-value str">''</span>
379:         <span class="ruby-identifier">extras</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;cc=#{CGI.escape(cc).gsub(&quot;+&quot;, &quot;%20&quot;)}&amp;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">cc</span>.<span class="ruby-identifier">nil?</span>
380:         <span class="ruby-identifier">extras</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;bcc=#{CGI.escape(bcc).gsub(&quot;+&quot;, &quot;%20&quot;)}&amp;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">bcc</span>.<span class="ruby-identifier">nil?</span>
381:         <span class="ruby-identifier">extras</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;body=#{CGI.escape(body).gsub(&quot;+&quot;, &quot;%20&quot;)}&amp;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">nil?</span>
382:         <span class="ruby-identifier">extras</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;subject=#{CGI.escape(subject).gsub(&quot;+&quot;, &quot;%20&quot;)}&amp;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">subject</span>.<span class="ruby-identifier">nil?</span>
383:         <span class="ruby-identifier">extras</span> = <span class="ruby-value str">&quot;?&quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">extras</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/&amp;?$/</span>,<span class="ruby-value str">&quot;&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">extras</span>.<span class="ruby-identifier">empty?</span>
384: 
385:         <span class="ruby-identifier">email_address</span> = <span class="ruby-identifier">email_address</span>.<span class="ruby-identifier">to_s</span>
386: 
387:         <span class="ruby-identifier">email_address_obfuscated</span> = <span class="ruby-identifier">email_address</span>.<span class="ruby-identifier">dup</span>
388:         <span class="ruby-identifier">email_address_obfuscated</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/@/</span>, <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;replace_at&quot;</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">&quot;replace_at&quot;</span>)
389:         <span class="ruby-identifier">email_address_obfuscated</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\./</span>, <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;replace_dot&quot;</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">&quot;replace_dot&quot;</span>)
390: 
391:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">encode</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;javascript&quot;</span>
392:           <span class="ruby-identifier">tmp</span> = <span class="ruby-node">&quot;document.write('#{content_tag(&quot;a&quot;, name || email_address, html_options.merge({ &quot;href&quot; =&gt; &quot;mailto:&quot;+email_address+extras }))}');&quot;</span>
393:           <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">tmp</span>.<span class="ruby-identifier">length</span>
394:             <span class="ruby-identifier">string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%%%x&quot;</span>,<span class="ruby-identifier">tmp</span>[<span class="ruby-identifier">i</span>])
395:           <span class="ruby-keyword kw">end</span>
396:           <span class="ruby-node">&quot;&lt;script type=\&quot;#{Mime::JS}\&quot;&gt;eval(unescape('#{string}'))&lt;/script&gt;&quot;</span>
397:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">encode</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;hex&quot;</span>
398:           <span class="ruby-identifier">email_address_encoded</span> = <span class="ruby-value str">''</span>
399:           <span class="ruby-identifier">email_address_obfuscated</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
400:             <span class="ruby-identifier">email_address_encoded</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;&amp;#%d;&quot;</span>, <span class="ruby-identifier">c</span>)
401:           <span class="ruby-keyword kw">end</span>
402: 
403:           <span class="ruby-identifier">protocol</span> = <span class="ruby-value str">'mailto:'</span>
404:           <span class="ruby-identifier">protocol</span>.<span class="ruby-identifier">each_byte</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;&amp;#%d;&quot;</span>, <span class="ruby-identifier">c</span>) }
405: 
406:           <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">email_address</span>.<span class="ruby-identifier">length</span>
407:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">email_address</span>[<span class="ruby-identifier">i</span>,<span class="ruby-value">1</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\w/</span>
408:               <span class="ruby-identifier">string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%%%x&quot;</span>,<span class="ruby-identifier">email_address</span>[<span class="ruby-identifier">i</span>])
409:             <span class="ruby-keyword kw">else</span>
410:               <span class="ruby-identifier">string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">email_address</span>[<span class="ruby-identifier">i</span>,<span class="ruby-value">1</span>]
411:             <span class="ruby-keyword kw">end</span>
412:           <span class="ruby-keyword kw">end</span>
413:           <span class="ruby-identifier">content_tag</span> <span class="ruby-value str">&quot;a&quot;</span>, <span class="ruby-identifier">name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">email_address_encoded</span>, <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">merge</span>({ <span class="ruby-value str">&quot;href&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{string}#{extras}&quot;</span> })
414:         <span class="ruby-keyword kw">else</span>
415:           <span class="ruby-identifier">content_tag</span> <span class="ruby-value str">&quot;a&quot;</span>, <span class="ruby-identifier">name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">email_address_obfuscated</span>, <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">merge</span>({ <span class="ruby-value str">&quot;href&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;mailto:#{email_address}#{extras}&quot;</span> })
416:         <span class="ruby-keyword kw">end</span>
417:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000912" class="method-detail">
        <a name="M000912"></a>

        <div class="method-heading">
          <a href="#M000912" class="method-signature">
          <span class="method-name">url_for</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the URL for the set of <tt>options</tt> provided. This takes the
same options as <a href="UrlHelper.html#M000912">url_for</a> in
ActionController (see the documentation for
ActionController::Base#url_for). Note that by default <tt>:only_path</tt>
is <tt>true</tt> so you&#8216;ll get the relative /controller/action
instead of the fully qualified URL like <a
href="http://example.com/controller/action">example.com/controller/action</a>.
</p>
<p>
When called from a view, <a href="UrlHelper.html#M000912">url_for</a>
returns an HTML escaped url. If you need an unescaped url, pass :escape
=&gt; false in the <tt>options</tt>.
</p>
<h4>Options</h4>
<ul>
<li><tt>:anchor</tt> &#8212; specifies the anchor name to be appended to the
path.

</li>
<li><tt>:only_path</tt> &#8212; if true, returns the relative URL (omitting the
protocol, host name, and port) (<tt>true</tt> by default unless
<tt>:host</tt> is specified)

</li>
<li><tt>:trailing_slash</tt> &#8212; if true, adds a trailing slash, as in
&quot;/archive/2005/&quot;. Note that this is currently not recommended
since it breaks caching.

</li>
<li><tt>:host</tt> &#8212; overrides the default (current) host if provided

</li>
<li><tt>:protocol</tt> &#8212; overrides the default (current) protocol if
provided

</li>
<li><tt>:user</tt> &#8212; Inline HTTP authentication (only plucked out if
:password is also present)

</li>
<li><tt>:password</tt> &#8212; Inline HTTP authentication (only plucked out if
:user is also present)

</li>
<li><tt>:escape</tt> &#8212; Determines whether the returned URL will be HTML
escaped or not (<tt>true</tt> by default)

</li>
</ul>
<h4>Relying on named routes</h4>
<p>
If you instead of a hash pass a record (like an Active Record or Active
Resource) as the options parameter, you&#8216;ll trigger the named route
for that record. The lookup will happen on the name of the class. So
passing a Workshop object will attempt to use the workshop_path route. If
you have a nested route, such as admin_workshop_path you&#8216;ll have to
call that explicitly (it&#8216;s impossible for <a
href="UrlHelper.html#M000912">url_for</a> to guess that route).
</p>
<h4>Examples</h4>
<pre>
  &lt;%= url_for(:action =&gt; 'index') %&gt;
  # =&gt; /blog/

  &lt;%= url_for(:action =&gt; 'find', :controller =&gt; 'books') %&gt;
  # =&gt; /books/find

  &lt;%= url_for(:action =&gt; 'login', :controller =&gt; 'members', :only_path =&gt; false, :protocol =&gt; 'https') %&gt;
  # =&gt; https://www.railsapplication.com/members/login/

  &lt;%= url_for(:action =&gt; 'play', :anchor =&gt; 'player') %&gt;
  # =&gt; /messages/play/#player

  &lt;%= url_for(:action =&gt; 'checkout', :anchor =&gt; 'tax&amp;ship') %&gt;
  # =&gt; /testing/jump/#tax&amp;amp;ship

  &lt;%= url_for(:action =&gt; 'checkout', :anchor =&gt; 'tax&amp;ship', :escape =&gt; false) %&gt;
  # =&gt; /testing/jump/#tax&amp;ship

  &lt;%= url_for(Workshop.new) %&gt;
  # relies on Workshop answering a new_record? call (and in this case returning true)
  # =&gt; /workshops

  &lt;%= url_for(@workshop) %&gt;
  # calls @workshop.to_s
  # =&gt; /workshops/5
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000912-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000912-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb, line 65</span>
65:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">options</span> = {})
66:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">options</span>
67:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
68:           <span class="ruby-identifier">show_path</span> =  <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:host</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
69:           <span class="ruby-identifier">options</span> = { <span class="ruby-identifier">:only_path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">show_path</span> }.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys</span>)
70:           <span class="ruby-identifier">escape</span>  = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">:escape</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:escape</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>
71:           <span class="ruby-identifier">url</span>     = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:url_for</span>, <span class="ruby-identifier">options</span>)
72:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
73:           <span class="ruby-identifier">escape</span> = <span class="ruby-keyword kw">true</span>
74:           <span class="ruby-identifier">url</span>    = <span class="ruby-identifier">options</span>
75:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">NilClass</span>
76:           <span class="ruby-identifier">url</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:url_for</span>, <span class="ruby-keyword kw">nil</span>)
77:         <span class="ruby-keyword kw">else</span>
78:           <span class="ruby-identifier">escape</span> = <span class="ruby-keyword kw">false</span>
79:           <span class="ruby-identifier">url</span>    = <span class="ruby-identifier">polymorphic_path</span>(<span class="ruby-identifier">options</span>)
80:         <span class="ruby-keyword kw">end</span>
81: 
82:         <span class="ruby-identifier">escape</span> <span class="ruby-value">? </span><span class="ruby-identifier">escape_once</span>(<span class="ruby-identifier">url</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">url</span>
83:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>